import QtQuick
import QtQuick.Controls

Rectangle {
    color: "lightgray"

    Column {
        anchors.centerIn: parent
        spacing: 10

        Button {
            text: "创建矩形"
            onClicked: {
                var component = Qt.createComponent("component/ColorRect.qml");
                if (component.status === Component.Ready) {
                    var object = component.createObject(container, {
                        "x": Math.random() * (container.width - 100),
                        "y": Math.random() * (container.height - 100)
                    });
                    if (object === null) {
                        console.log("Error creating object");
                    }
                } else if (component.status === Component.Error) {
                    console.log("Error loading component:", component.errorString());
                }
            }
        }

        Rectangle {
            id: container
            width: 300
            height: 300
            color: "white"
            border.color: "black"
        }
    }
}
